﻿@using CuongHanh
@{
    ViewBag.Title = "Bộ Sưu Tập";
    Layout = "~/Views/Shared/_ALayout.cshtml";

}
@section script
{
    <script type="text/javascript">
        function search() {
            window.App.gvData.store.proxy.extraParams.query = window.App.txtSearch.getValue();
            window.App.gvData.store.load();
        }
    </script>
}
@(Html.X()
          .Viewport()
          .Layout(LayoutType.Border)
          .Items(view =>
                     {
                         Toolbar topMenu = new Toolbar
                                               {
                                                       Region = Region.North
                                               };
                         view.Add(topMenu);
                         topMenu.Add(Html.X()
                                             .Label()
                                             .Text("Tìm kiếm: "));
                         topMenu.Add(Html.X()
                                             .TextField()
                                             .ID("txtSearch")
                                             .Width(550)
                                             .EmptyText("Tìm kiếm theo: Tên"));
                         topMenu.Add(Html.X()
                                             .Button()
                                             .Icon(Icon.Find)
                                             .Text("Xem")
                                             .OnClientClick("search")
                                 );
                         topMenu.Add(new ToolbarFill());
                         topMenu.Add(Html.X()
                                             .Button()
                                             .Text("Thêm bộ sưu tập")
                                             .Icon(Icon.Add)
                                             .DirectEvents(de =>
                                                               {
                                                                   de.Click.Url = Url.Action("ShowAdd");
                                                                   de.Click.ExtraParams.Add(new Parameter("containerId",
                                                                                                          "wdModify"));
                                                                   de.Click.ExtraParams.Add(new Parameter("branchId",
                                                                                                          ViewBag.branchId + ""));
                                                               })
                                 );

                         view.Add(Html.X()
                                          .GridPanel()
                                          .ForceFit(true)
                                          .ID("gvData")
                                          .View(Html.X()
                                                        .GridView()
                                                        .EnableTextSelection(true)
                                          )
                                          .Region(Region.Center)
                                          .ColumnModel(column =>
                                                           {
                                                               column.Add(Html.X()
                                                                                  .Column()
                                                                                  .DataIndex("NameVi")
                                                                                  .Text("Tên T.Việt")
                                                                       );
                                                               column.Add(Html.X()
                                                                                  .Column()
                                                                                  .DataIndex("NameEn")
                                                                                  .Text("Tên T.Anh")
                                                                       );
                                                               column.Add(Html.X()
                                                                                  .Column()
                                                                                  .DataIndex("NameZh")
                                                                                  .Text("Tên T.Hoa")
                                                                       );
                                                               
                                                               column.Add(Html.X()
                                                                                  .CommandColumn()
                                                                                  .MinWidth(65)
                                                                                  .MaxWidth(65)
                                                                                  .Commands(v => v.Add(new GridCommand
                                                                                                           {
                                                                                                                   Icon = Icon.TableEdit,
                                                                                                                   CommandName = "Edit",
                                                                                                                   Text = "Sửa"
                                                                                                           })
                                                                                  )
                                                                                  .DirectEvents(de =>
                                                                                                    {
                                                                                                        de.Command.EventMask.ShowMask = true;
                                                                                                        de.Command.ExtraParams.Add(new Parameter("containerId",
                                                                                                                                                 "wdModify"));
                                                                                                        de.Command.ExtraParams.Add(new Parameter("command",
                                                                                                                                                 "command",
                                                                                                                                                 ParameterMode.Raw));
                                                                                                        de.Command.ExtraParams.Add(new Parameter("id",
                                                                                                                                                 "record.data.Id",
                                                                                                                                                 ParameterMode.Raw));
                                                                                                        de.Command.Url = Url.Action("Command");
                                                                                                        de.AutoDataBind = true;
                                                                                                    })
                                                                       );

                                                               column.Add(Html.X()
                                                                                  .CommandColumn()
                                                                                  .Width(120)
                                                                                  .PaddingSpec("0 10")
                                                                                  .Align(Alignment.Center)
                                                                                  .Commands(v =>
                                                                                            v.Add(new GridCommand
                                                                                                      {
                                                                                                              Icon = Icon.Delete,
                                                                                                              CommandName = "Delete",
                                                                                                              Text = "Xóa"
                                                                                                      })
                                                                                  )
                                                                                  .DirectEvents(de =>
                                                                                                    {
                                                                                                        de.Command.EventMask.ShowMask = true;
                                                                                                        de.Command.ExtraParams.Add(new Parameter("containerId",
                                                                                                                                                 "wdModify"));
                                                                                                        de.Command.ExtraParams.Add(new Parameter("command",
                                                                                                                                                 "command",
                                                                                                                                                 ParameterMode.Raw));
                                                                                                        de.Command.ExtraParams.Add(new Parameter("id",
                                                                                                                                                 "record.data.Id",
                                                                                                                                                 ParameterMode.Raw));
                                                                                                        de.Command.Url = Url.Action("Command");
                                                                                                        de.Command.Confirmation.ConfirmRequest = true;
                                                                                                        de.Command.Confirmation.BeforeConfirm = "config.confirmation.title = 'Thông báo'; config.confirmation.message = 'Bạn có muốn xóa bộ sưu tập này không?';";
                                                                                                        de.AutoDataBind = true;
                                                                                                    })
                                                                       );
                                                           })
                                          .BottomBar(Html.X()
                                                             .PagingToolbar())
                                          .Store(Html.X()
                                                         .Store()
                                                         .RemotePaging(true)
                                                         .PageSize(30)
                                                         .ID("storeGvData")
                                                         .AutoLoad(true)
                                                         .AutoSync(false)
                                                         .Model(c => c.Add(Html.X()
                                                                                   .Model()
                                                                                   .Fields("Id",
                                                                                           "NameVi",
                                                                                           "NameEn",
                                                                                           "NameZh",
                                                                                           "Code",
                                                                                           "No",
                                                                                           "BranchId",
                                                                                           "LastModified"
                                                                                   )
                                                                                   .IDProperty("Id")))
                                                         .Proxy(c => c.Add(Html.X()
                                                                                   .AjaxProxy()
                                                                                   .Json(true)
                                                                                   .Url(Url.Action("GetDatas"))
                                                                                   .ActionMethods(v => v.Read = HttpMethod.POST)
                                                                                   .Reader(Html.X()
                                                                                                   .JsonReader()
                                                                                                   .Root("data")
                                                                                                   .TotalProperty("total"))
                                                                                   .ExtraParams(param =>
                                                                                                    {
                                                                                                        param.Add(new Parameter("query",
                                                                                                                                "",
                                                                                                                                ParameterMode.Value));
                                                                                                        param.Add(new Parameter("branchId",
                                                                                                                                ViewBag.branchId + "",
                                                                                                                                ParameterMode.Value));
                                                                                                    }
                                                                                   )
                                                                             ))
                                                         .AutoLoadParams(c =>
                                                                             {
                                                                                 c.Add(new Parameter("start",
                                                                                                     "0",
                                                                                                     ParameterMode.Raw));
                                                                                 c.Add(new Parameter("limit",
                                                                                                     "30",
                                                                                                     ParameterMode.Raw));
                                                                             }))
                                 );
                     }))


@(Html.X()
          .Window()
          .ID("wdModify")
          .Hidden(true)
          .Modal(true)
          .Resizable(false)
          .Title("Thông tin bộ sưu tập")
          .Width(700)
          .Height(530)
          .Constrain(true)
          .StyleHtmlCls("background-color:white;")
          )